package org.neu.ccs.secureim;

import java.security.Permission;
import java.util.HashMap;
import java.util.HashSet;

public class SIMSSecurityManager extends SecurityManager {
	
	HashMap<String, Integer> connectionTable;
	
	public SIMSSecurityManager()
	{
		super();
		connectionTable = new HashMap<String, Integer>();
	}
	
	public void remove(String host)
	{
		int num = connectionTable.get(host);
		connectionTable.remove(host);
		connectionTable.put(host, num--);
	}
	
	@Override
	public void checkPropertyAccess(String key)
	{
		
	}
	
	@Override
	public void checkRead(String file)
	{}
	
	@Override
	public void checkWrite(String file)
	{}
	
	@Override
	public void checkPermission(Permission perm)
	{}
	
	@Override
	public void checkAccept(String host, int port)
	{
		if( !connectionTable.containsKey(host) )
			connectionTable.put(host, 0);
		int num = connectionTable.get(host);
		if( num > 5 )
			throw new SecurityException("Too many connections from " + host);
		
		num++;
		connectionTable.remove(host);
		connectionTable.put(host, num);
	}

}
